<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Canvas</title>
</head>

<body>
    <canvas id="canvasElem" width="400px" height="300px"></canvas>

    <script>
        var canvas = document.getElementById('canvasElem'); // 获得画布对象
        var context = canvas.getContext('2d'); // 准备画笔，获得上下文
        context.lineWidth = '10'; //设置线宽
        context.strokeStyle = '#f00'
        context.lineCap = 'round';
        context.moveTo(10, 120); //端点
        context.lineTo(50, 120); //端点
        context.lineTo(10, 150); //端点
        context.lineTo(50, 150); //端点

        context.moveTo(100, 100); //端点
        context.lineTo(100, 150); //端点
        context.lineTo(150, 150); //端点
        context.lineTo(150, 100); //端点
        context.lineTo(100, 100); // 描边
        context.stroke(); // 描边
    </script>
</body>

</html>